from fastapi import FastAPI, Query
from typing import List

app = FastAPI(title="城市酒店服务")

SUPPORTED_CITIES = ["北京", "上海", "广州", "深圳", "成都", "杭州"]
HOTELS = {
    "北京": ["北京国际大酒店", "北京丽都酒店"],
    "上海": ["上海浦东大酒店", "上海外滩酒店"],
    "广州": ["广州白云宾馆", "广州花园酒店"],
    "深圳": ["深圳福田酒店", "深圳罗湖酒店"],
    "成都": ["成都锦江宾馆", "成都环球中心酒店"],
    "杭州": ["杭州西湖大酒店", "杭州滨江酒店"]
}

@app.get("/cities", response_model=List[str])
def get_cities():
    """查询支持的城市列表"""
    return SUPPORTED_CITIES

@app.get("/hotels")
def get_hotels(city: str = Query(..., description="城市名")):
    """查询指定城市的酒店房间列表（模拟数据）"""
    if city not in HOTELS:
        return {"error": "不支持该城市"}
    return {"city": city, "hotels": HOTELS[city]}

@app.post("/reserve")
def reserve_hotel(city: str = Query(...), hotel: str = Query(...)):
    """预定指定城市的酒店房间（模拟数据）"""
    if city not in HOTELS or hotel not in HOTELS[city]:
        return {"error": "城市或酒店不存在"}
    return {"msg": f"已成功预定 {city} 的 {hotel}"}
